package com.mh.controller;

import com.mh.dto.R;
import com.mh.dto.vo.OrderShowVo;
import com.mh.pojo.OrderInfos;
import com.mh.service.OrderInfosService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Date:2024/10/29
 * author:zmh
 * description: 订单信息相关接口
 **/

@RestController
@RequestMapping("/orderInfos")
@CrossOrigin
@Slf4j
@RequiredArgsConstructor
public class OrderInfosController {

    private final OrderInfosService  orderInfosService;

    /**
     * 获取指定用户的所有订单
     * @param userId 用户ID
     * @return ·
     */
    @GetMapping("/getAllOrderByUserId/{userId}")
    public R<List<OrderShowVo>> getAllOrderByUserId(@PathVariable String userId) {
        return orderInfosService.getAllOrderByUserId(userId);
    }

    /**
     * 根据用户ID获取各订单状态数量，用于展示徽标
     * @param userId ·
     * @return ·
     */
    @GetMapping("/getOrderStatusCount/{userId}")
    public R<Map<Integer, Long>> getOrderStatusCount(@PathVariable String userId) {
        return orderInfosService.getOrderStatusCount(userId);
    }

    /**
     * 根据订单ID获取订单信息
     * @param orderId ��ID
     * @return ·
     */
    @GetMapping("/getOrderInfoById/{orderId}")
    public R<OrderInfos> getOrderInfoById(@PathVariable String orderId) {
        return orderInfosService.getOrderInfoById(orderId);
    }

    /**
     * 根据订单ID取消订单
     * @param orderId 订单ID
     * @return ·
     */
    @PutMapping("/cancelOrder/{orderId}")
    public R<String> cancelOrder(@PathVariable String orderId) {
        return orderInfosService.cancelOrder(orderId);
    }

    /**
     * 根据订单ID删除订单
     * @param orderId 订单ID
     * @return ·
     */
    @DeleteMapping("/deleteOrder/{orderId}")
    public R<String> deleteOrder(@PathVariable String orderId) {
        return orderInfosService.deleteOrder(orderId);
    }

}
